package cn.net.zidian.mvvm.vm;

import com.blankj.utilcode.util.ToastUtils;
import com.chad.library.adapter.base.entity.MultiItemEntity;

import java.util.ArrayList;
import java.util.List;

import cn.net.zidian.api.ApiRepository;
import cn.net.zidian.bean.AstroDetailsBean;
import cn.net.zidian.bean.MultiItemEntityC;
import cn.net.zidian.bean.ResultBean;
import cn.net.zidian.event.SingleLiveEvent;
import io.reactivex.rxjava3.annotations.NonNull;
import io.reactivex.rxjava3.observers.DisposableObserver;

public class AstroDetailsVM extends BaseViewModel {

    public SingleLiveEvent<List<MultiItemEntity>> eventList = new SingleLiveEvent<>();

    public void getList(String id) {
        ApiRepository.getAstroDetails(id)
                .safeSubscribe(new DisposableObserver<ResultBean<AstroDetailsBean>>() {
                    @Override
                    public void onNext(@NonNull ResultBean<AstroDetailsBean> result) {
                        if (result.getStatus() == 0) {
                            List<MultiItemEntity> list = new ArrayList<>();
                            list.add(new MultiItemEntityC(result.getResult().getToday(), 1));
                            list.add(new MultiItemEntityC(result.getResult().getTomorrow(), 1));
                            list.add(new MultiItemEntityC(result.getResult().getWeek(), 2));
                            list.add(new MultiItemEntityC(result.getResult().getMonth(), 2));
                            list.add(new MultiItemEntityC(result.getResult().getYear(), 2));
                            eventList.setValue(list);
                        } else {
                            ToastUtils.showShort(result.getMsg());
                        }
                    }

                    @Override
                    public void onError(@NonNull Throwable e) {
                        ToastUtils.showShort("网络请求失败");
                    }

                    @Override
                    public void onComplete() {

                    }
                });

    }
}
